﻿
/// <summary>
/// 
/// </summary>
[Authorize(Roles = "None")]
public partial class ProjectController : Controller
{
    private readonly ProjectService _projectService;

    public ProjectController(ProjectService projectService)
    {
        _projectService = projectService;
    }

    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <returns></returns>
    [HttpPost("project/pages")]
    public async Task<RestfulResult<PageResult<GanttProject>>> GetPagesAsync()
    {
        using var sr = new StreamReader(Request.Body);
        string dataStr = await sr.ReadToEndAsync();
        if (Request.Body.CanSeek)
            Request.Body.Position = 0;
        if (string.IsNullOrWhiteSpace(dataStr))
            throw new Exception("未提供上传数据。请在Request.Body中携带上传数据。");

        PageParam? data = JsonConvert.DeserializeObject<PageParam>(dataStr);
        data ??= new PageParam { PageNo = 1, PageSize = 10 };

        return await _projectService.GetPagesAsync(data);
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <returns></returns>
    [HttpPost("project/list")]
    public async Task<RestfulResult<PageResult<ProjectDto>>> GetlistAsync()
    {
        return await _projectService.GetlistAsync();
    }
    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("project/submit")]
    public async Task<RestfulResult> SubmitAsync([FromBody] GanttProject data)
    {
        return await _projectService.SubmitAsync(data);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("project/delete/{id:long}")]
    public async Task<RestfulResult> DeleteAsync(long id)
    {
        return await _projectService.DeleteAsync(id);
    }
}